#!/usr/bin/env python
# -*- coding: latin-1; py-indent-offset:4 -*-
################################################################################
# 
# This file is part of Bfplusplus
#
# Bfplusplus is a graphical interface to the Betfair Betting Exchange
# Copyright (C) 2010 Daniel Rodriguez (aka Daniel Rodriksson)
# Copyright (C) 2011 Sensible Odds Ltd.
#
# You can learn more and contact the author at:
#
#    http://code.google.com/p/bfplusplus/
#
# Bfplusplus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bfplusplus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bfplusplus. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""Subclass of ProgressDialog, which is generated by wxFormBuilder."""

import MainGui

import wx

# Implementing ProgressDialog
class ProgressDialog(MainGui.ProgressDialog):

    timerInc = 0.100

    def __init__(self, parent, timeOut=14.0):
	MainGui.ProgressDialog.__init__(self, parent)

        self.timeOut = timeOut
        self.timerCount = 0
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

        if self.CanSetTransparent() == True:
            self.SetTransparent(128)


    def OnClose(self, event):
	event.Veto()


    def OnTimer(self, event):
        event.Skip()

        if self.timerCount >= self.timeOut:
            self.Show(False)
            return
        
        self.timerCount += self.timerInc
        self.m_gaugeLoading.SetValue(self.timerCount/self.timerInc)


    def Show(self, p_show):

        if p_show == True and self.IsShown() == True:
            self.Show(False)

        if p_show == False and self.IsShown() == False:
            self.Show(True)

	if p_show == True:
            self.m_gaugeLoading.SetValue(0)
            self.m_gaugeLoading.SetRange(self.timeOut / self.timerInc)

            self.timerCount = 0
            self.timer.Start(self.timerInc * 1000)

            self.SetRect(self.GetParent().GetScreenRect())
        else: # p_show is False
            self.timer.Stop()

	MainGui.ProgressDialog.Show(self, p_show)
